/**
 * 
 */
package org.youisoft.summer.evaluator.unit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.youisoft.summer.evaluator.InvokeException;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.operator.Operator;

/**
 * 
 * @author zijiang.jl
 * 
 * 访问者类，提供对Unit访问。
 *
 * @param <R>
 * @param <P>
 */
public final class UnitVisitor<R,P> {
	
	protected static final Log logger=LogFactory.getLog(UnitVisitor.class);
	private Operator<?> value=Operator.nullInstance;
	private R resource;
	private P property;
    


	/**
	 * 
	 * @param <C>
	 * @param context
	 * @param unit
	 * @throws InvokeException
	 */
	public <C> void visit(CalContext<C,R,P> context,VisitorUnit<R,P> unit) throws InvokeException{
		if(this.value==null) value=Operator.nullInstance;
		this.value=unit.calculate(context, this.value);
		
	}


	public final void setValue(Operator<?> value) {
		this.value = value;
	}


	/**
	 * 
	 * @return
	 */
	public Operator<?> getValue() {
		return this.value;
	}

	/**
	 * 
	 * @return
	 */
	public P getProperty() {
		return property;
	}

	/**
	 * 
	 * @param property
	 */
	public void setProperty(P property) {
		this.property = property;
	}


	/**
	 * 
	 * @param resource
	 */
	public void setResource(R resource) {
		this.resource=resource;
		
	}

	

	/**
	 * 
	 * @return
	 */
	public R getResource() {
		return this.resource;
	}
}
